import sys
import functools
from PyQt5.QtCore import pyqtSlot, Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QCheckBox, QButtonGroup,QLabel

def on_state_changed(index, arg):
    print(f"btn: {index}", end = "")
    if arg == Qt.Checked:
        print("选中")
    else:
        print("取消")
        
def init_widget(w: QWidget):
    w.setWindowTitle("多选框")
    layout = QHBoxLayout()
    w.setLayout(layout)
    
    btn1 = QCheckBox("抽烟")
    btn2 = QCheckBox("喝酒")
    btn3 = QCheckBox("烫头")
    btn3.setChecked(True)
    
    btn1.stateChanged.connect(lambda arg: on_state_changed(1, arg))
    btn2.stateChanged.connect(functools.partial(on_state_changed, 2))
    btn3.stateChanged.connect(lambda arg:print("按钮3", arg))
    
    layout.addWidget(QLabel("谦哥的三大爱好："))
    layout.addWidget(btn1)
    layout.addWidget(btn2)
    layout.addWidget(btn3)
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = QWidget()
    init_widget(w)
    w.show()
    sys.exit(app.exec_())

    